<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运行监控</title>
    <link rel="stylesheet" href="/businessProcessManager/js/ele/index.css">
    <link rel="stylesheet" href="/businessProcessManager/css/style.css">
</head>
<body>
<header>
    <img src="/businessProcessManager/images/logo.png" alt="">
    <span class="com-name">业务流程管理平台</span>
</header>
<div>
    <div class="side" id="side">
        <div id="menu" class="menu">
            <el-menu default-active="2" unique-opened class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose">
                <el-submenu index="1">
                    <template slot="title"><i class="el-icon-menu"></i>业务流程管理</template>
                   <!-- <a href="/businessProcessManager/html/process.html"><el-menu-item index="1-1">流程管理</el-menu-item></a>-->
                    <a href="/businessProcessManager/html/process-list.html"><el-menu-item index="1-1">流程定义</el-menu-item></a>
                    <!--<a href="/businessProcessManager/html/sortManager.html"><el-menu-item index="1-2">分类管理</el-menu-item></a>-->
                    <a href="/businessProcessManager/html/run-task.html"><el-menu-item index="1-3">待办任务</el-menu-item></a>
                    <a href="/businessProcessManager/html/monitor.html"><el-menu-item index="1-3">运行监控</el-menu-item></a>
                    <!--<a href="/businessProcessManager/html/task-entrust.html"><el-menu-item index="1-4">任务委托</el-menu-item></a>-->
                    <a href="/businessProcessManager/html/model-list.html"><el-menu-item index="1-4">模型管理</el-menu-item></a>
                    <!--<a href="user-group.html"><el-menu-item index="1-5">用户分组</el-menu-item></a>
                    <a href="dataAllocation.html"><el-menu-item index="1-6">数据配置</el-menu-item></a>
                    <a href="exampleAllocation.html"><el-menu-item index="1-7">实例配置</el-menu-item></a>-->
                </el-submenu>
            </el-menu>

        </div>
    </div>
    <div class="main-wrapper " >
        <div class="nav-bar">
            <span class="position-info">您现在的位置：<a>公文管理</a> &gt; <span class="current-position">公文会签</span></span>
        </div>
        <div class="content-wrapper" style="top: 45px;">
            <div id="tab" class="run-detail relative">
                <el-tabs v-model="activeName">
                    <el-tab-pane label="按流程" name="first">
                        <div class="table-box">
                            <div class="center">
                                <el-table
                                        :data="processInstances"
                                        border
                                        height="600"
                                        @selection-change="">
                                    <el-table-column
                                            type="index"
                                            width="80"
                                            label="序号">
                                    </el-table-column>
                                    <el-table-column
                                            prop="id"
                                            label="流程实例ID"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="processDefinitionId"
                                            label="流程定义ID">
                                    </el-table-column>
                                    <el-table-column
                                            prop="processDefinitionKey"
                                            label="流程定义key">
                                    </el-table-column>
                                    <el-table-column
                                            prop="businessKey"
                                            label="业务表单key">
                                    </el-table-column>
                                    <el-table-column
                                            prop="activityId"
                                            label="当前任务ID"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            label="是否暂停"
                                    >
                                        <template scope="scope">
                                            <span v-if="scope.row.suspended==false">否</span>
                                            <span v-else>是</span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column
                                            label="完成情况">
                                        <template scope="scope">
                                            <span v-if="scope.row.ended==false">未完成</span>
                                            <span v-else>完成</span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column
                                            label="操作"
                                            width="120">
                                        <template scope="scope">
                                            <el-button @click="cancelEntrust(scope.row)" type="text" >运行明细</el-button>
                                            <el-button @click="deleteProcessInstace(scope.row)" type="text" >删除</el-button>
                                            <el-button v-if="scope.row.suspended==false" @click="suspendProcessInstance(scope.row)" type="text" >暂停</el-button>
                                            <el-button v-if="scope.row.suspended==true" @click="activateProcessInstance(scope.row)" type="text" >激活</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                            <div class="page-box mt20 text-right">
                                <el-pagination
                                        @current-change="handleCurrentChange"
                                        :page-size="size"
                                        layout="total, prev, pager, next"
                                        :total="total">
                                </el-pagination>
                            </div>
                        </div>
                    </el-tab-pane>
                    <!--<el-tab-pane label="按部门" name="second">
                        <div  class="tree-wrapper">
                            <el-tree
                                    :data="data2"
                                    node-key="id"
                                    ref="tree"
                                    highlight-current
                                    :expand-on-click-node="false"
                                    @node-click="getKey"
                                    :props="defaultProps">
                            </el-tree>
                        </div>
                        <div class="table-box" style="margin-left: 200px">
                            <div class="form-box">
                                <el-form :inline="true" :model="detailForm2" class="demo-form-inline">
                                    <el-form-item label="开始时间：" :label-width="formLabelWidth">
                                        <el-date-picker
                                                v-model="detailForm2.startTime"
                                                type="date"
                                                placeholder="选择日期"
                                        >
                                        </el-date-picker>
                                    </el-form-item>
                                    <el-form-item label="结束时间：" :label-width="formLabelWidth">
                                        <el-date-picker
                                                v-model="detailForm2.endTime"
                                                type="date"
                                                placeholder="选择日期">
                                        </el-date-picker>
                                    </el-form-item>
                                    <el-form-item label=" " :label-width="formLabel2Width">
                                        <el-button type="primary" @click="query">查询</el-button>
                                    </el-form-item>

                                </el-form>
                            </div>
                            <div class="center">
                                <el-table
                                        :data="processInstances"
                                        border
                                        height="600"
                                        @selection-change="">
                                    <el-table-column
                                            type="index"
                                            width="80"
                                            label="序号">
                                    </el-table-column>
                                    <el-table-column
                                            prop="task"
                                            label="任务环节"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="startTime"
                                            label="开始时间">
                                    </el-table-column>

                                    <el-table-column
                                            prop="endTime"
                                            label="完成时间"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="transacter"
                                            label="办理人"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="transactTimes"
                                            label="办理时长"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="status"
                                            label="状态"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            label="操作"
                                            width="120">
                                        <template scope="scope">
                                            <a href="#">运行明细</a>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="按办理人" name="third">
                        <div class="tree-wrapper">
                            <el-tree
                                    :data="data2"
                                    node-key="id"
                                    ref="tree"
                                    highlight-current
                                    :expand-on-click-node="false"
                                    @node-click="getKey"
                                    :props="defaultProps">
                            </el-tree>
                        </div>
                        <div class="table-box" style="margin-left: 200px">
                            <div class="form-box">
                                <el-form :inline="true" :model="detailForm3" class="demo-form-inline">
                                    <el-form-item label="开始时间：" :label-width="formLabelWidth">
                                        <el-date-picker
                                                v-model="detailForm3.startTime"
                                                type="date"
                                                placeholder="选择日期"
                                        >
                                        </el-date-picker>
                                    </el-form-item>
                                    <el-form-item label="结束时间：" :label-width="formLabelWidth">
                                        <el-date-picker
                                                v-model="detailForm3.endTime"
                                                type="date"
                                                placeholder="选择日期"
                                        >
                                        </el-date-picker>
                                    </el-form-item>
                                    <el-form-item label=" " :label-width="formLabel2Width">
                                        <el-button type="primary" @click="query">查询</el-button>
                                    </el-form-item>

                                </el-form>
                            </div>
                            <div class="center">
                                <el-table
                                        :data="processInstances"
                                        border
                                        height="600"
                                        @selection-change="">
                                    <el-table-column
                                            type="index"
                                            width="80"
                                            label="序号">
                                    </el-table-column>
                                    <el-table-column
                                            prop="task"
                                            label="任务环节"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="startTime"
                                            label="开始时间">
                                    </el-table-column>

                                    <el-table-column
                                            prop="endTime"
                                            label="完成时间"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="transacter"
                                            label="办理人"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="transactTimes"
                                            label="办理时长"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            prop="status"
                                            label="状态"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                            label="操作"
                                            width="120">
                                        <template scope="scope">
                                            <a href="#">运行明细</a>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                    </el-tab-pane>-->
                </el-tabs>
            </div>
        </div>
        <div class="foot-biu">
             四川新迎顺信息技术股份有限公司
        </div>
    </div>
</div>

<!-- 先引入 Vue -->
<script src="/businessProcessManager/js/ele/vue.js"></script>
<script src="/businessProcessManager/js/ele/vue-resource.js"></script>
<script src="/businessProcessManager/js/ele/vue-router.js"></script>
<!-- 引入组件库 -->
<script src="/businessProcessManager/js/ele/index.js"></script>
<script src="/businessProcessManager/js/jquery.min.js"></script>
<script src="/businessProcessManager/js/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="/businessProcessManager/js/date.js"></script>
<!--引入url配置文件-->
<script src="/businessProcessManager/js/config.js"></script>
<script>
    //日期格式化
    function formatDates(time){
        return formatDate(new Date(time),'yyyy-MM-dd hh:mm');
    };
//
    var menu = new Vue({
        el:'#menu',
        methods: {
            handleOpen:function(key, keyPath) {
                console.log(key, keyPath);
            },
            handleClose:function(key, keyPath) {
                console.log(key, keyPath);
            }
        }
    });

    var tab = new Vue({
        el:'#tab',
        data:{
            activeName: 'first',
            formLabelWidth:'85px',
            formLabel2Width:'30px',
            detailForm:{
                startTime:'',
                endTime:''
            },
            detailForm2:{
                startTime:'',
                endTime:''
            },
            detailForm3:{
                startTime:'',
                endTime:''
            },
            defaultProps: {
                children: 'children',
                label: 'NAME'
            },
            processInstances:[],
            total:0 ,
            currentPage: 1,
            size: 10
        },
        created:function(){
            this.getProcessInstances();
        },
        methods:{
            //分页查询
            handleCurrentChange:function(data){
                var start=(data-1)*10;
                this.$http.get(url+portP+"runtime/process-instances?start="+start).then(function(data){
                    tab.processInstances=data.data.data;
                },function(response){
                    console.info(response);
                })
            },
            //格式化开始时间
            dateFormatStartTime:function(data,row){
                if(data.startTime!=null){
                    return formatDates(data.startTime);
                }
            },
            //格式化结束时间
            dateFormatEndTime:function(data,row){
                if(data.endTime!=null){
                    return formatDates(data.endTime);
                }
            },
        	//获取流程实例表
        	getProcessInstances:function(){
                this.$http.get(url+portP+"runtime/process-instances").then(function(data){
                	tab.processInstances=data.data.data;
                    tab.total = data.data.total;
                },function(response){
                    console.info(response);
                })
            },
            //毫秒转化为分钟
            durationInMillisFormatter:function(data,row){
        	    if(data.durationInMillis!=null){
                    return (data.durationInMillis/60000).toFixed(0)+"分钟";
                }
            },
            //运行明细
            cancelEntrust:function(data){
            	window.location.href=url+portC+"businessProcessManager/html/run-detail.html?processInstanceId="+data.id+"&processDefinitionId="+data.processDefinitionId;
            },
            //删除流程实例
            deleteProcessInstace:function(data){
                var self=this;
                this.$http.delete(url+portP+"runtime/process-instances/"+data.id).then(function(data){
                    self.$message({
                        message: data.data.data,
                        type: 'warning'
                    });
                    //document.location.reload();
                    self.getProcessInstances();
                });
            },
            //暂停流程实例
            suspendProcessInstance:function(data){
                var self=this;
                this.$http.put(url+portP+"runtime/process-instances/"+data.id,{"action":"suspend"}).then(function(data){
                    var message;
                    if(data.data.suspended==true){
                        message= "暂停成功";
                    }else{
                        message= "暂停失败";
                    }
                    self.$message({
                        message: message,
                        type: 'warning'
                    });
                    //document.location.reload();
                    self.getProcessInstances();
                });

            },
            //激活流程实例
            activateProcessInstance:function(data){
                var self=this;
                this.$http.put(url+portP+"runtime/process-instances/"+data.id,{"action":"activate"}).then(function(data){
                    var message;
                    if(data.data.suspended==false){
                        message= "激活成功";
                    }else{
                        message= "激活失败";
                    }
                    self.$message({
                        message: message,
                        type: 'warning'
                    });
                    //document.location.reload();
                    self.getProcessInstances();
                });
            },
        }
    })
</script>
</body>
</html>
